<template>
  <div>
    <wy-banner></wy-banner>
    <div>
      <div class="container">
        <!--机型、故障、价格-->
        <div class="content back-color-gray padding-left-13">
          <div class="text-style">
            <p>
              手机型号：{{customerInfo.brandName}}&nbsp;&nbsp;{{customerInfo.modelName}}&nbsp;&nbsp;{{customerInfo.deviceColor}}
            </p>
            <p> <span v-for="item in customerInfo.orderFailures" :key='item.id'>{{item.failureSubName}}</span></p>
            <p>预计费用： <span class="text-warning">￥{{customerInfo.price}}</span>（维修完成后付款）</p>
          </div>
        </div>

        <!--用户信息-->
        <div class="content">
          <el-row>
            <el-col :span="2">
              <div class="item-label">服务方式：</div>
            </el-col>
            <el-col :span="22">
              <div class="botton" v-for="iType in serviceType" @click="selectserverType(iType.value)"
                :class="iType.value==customerInfo.serviceType?'select-server':''" :key='iType.id'>
                {{iType.label}}
              </div>
            </el-col>
          </el-row>
          <!--上门-->
          <template v-if="customerInfo.serviceType=='SM'">
            <el-row>
              <el-col :span="2">
                <div class="item-label">所在城市：</div>
              </el-col>
              <el-col :span="10" class="padding-top-16">
                <el-cascader :props="props" :options="cityList" v-model="selectcity"></el-cascader>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="2">
                <div class="item-label">详细地址：</div>
              </el-col>
              <el-col :span="22" class="padding-top-10">
                <input type="text" class="input-text" placeholder="请填写详细上门维修地址或设备维修地址"
                  v-model="customerInfo.orderElement.address" />
              </el-col>
            </el-row>
          </template>
          <!--到店-->
          <template v-if="customerInfo.serviceType=='DD'">
            <el-row>
              <el-col :span="2">
                <div class="item-label">到店时间：</div>
              </el-col>
              <el-col :span="10" class="padding-top-16">
                <input type="text" class="input-text" placeholder="输入你到店时间" v-model="selectTime" />
              </el-col>
            </el-row>
          </template>
          <!--公用信息-->
          <el-row>
            <el-col :span="2">
              <div class="item-label">预约信息：</div>
            </el-col>
            <el-col :span="22">
              <el-row :gutter="20">
                <el-col :span="12" class="padding-top-10">
                  <input type="text" class="input-text" placeholder="您的姓名"
                    v-model="customerInfo.orderElement.customerName" />
                </el-col>
                <el-col :span="12" class="padding-top-10">
                  <input type="text" class="input-text" placeholder="您的联系方式"
                    v-model="customerInfo.orderElement.telephoneNo" />
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="2">
              <div class="item-label">备注 ：</div>
            </el-col>
            <el-col :span="22" class="padding-top-10">
              <textarea class="input-text" style="padding-top: 10px;height: 80px;" placeholder="请详细描述故障或其他要求。（选填）"
                v-model="customerInfo.address"></textarea>
            </el-col>
          </el-row>

          <!--店铺信息-->
          <template v-if="customerInfo.serviceType=='DD'">
            <el-row>
              <el-col :span="2">
                <div class="item-label">选择店铺：</div>
              </el-col>
              <el-col :span="10" class="padding-top-16">
                <el-select v-model="selectShop" placeholder="维修师浦东张江店(默认)"
                  style="width: 100%; border:1px solid #4FC1E9;border-radius:4px ;" @change="showOneStore">
                  <el-option v-for="item in storeSlots" :key="item.id" :label="item.shopName" :value="item.id">
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="3">
                <div class="item-label text-right">店铺名：</div>
              </el-col>
              <el-col :span="9" style="line-height: 70px;color: #999;">
                {{storeInfo.shopName}}
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="2">
                <div class="item-label">联系人：</div>
              </el-col>
              <el-col :span="10" style="line-height: 70px;color: #999;">
                {{storeInfo.name}}
              </el-col>
              <el-col :span="3">
                <div class="item-label text-right">电话：</div>
              </el-col>
              <el-col :span="9" style="line-height: 70px;color: #999;">
                {{storeInfo.phone}}
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="2">
                <div class="item-label">店铺地址：</div>
              </el-col>
              <el-col :span="10" style="line-height: 70px;color: #999;">
                {{storeInfo.adrress}}
              </el-col>
            </el-row>
          </template>
          <div class="padding-top-16 text-center">
            <el-checkbox v-model="customerInfo.protocol">我已详细阅读并同意</el-checkbox>
            <span @click="protocolDialogVisible = true" class="font-style-primary">《维修师服务协议》</span>
          </div>
          <div class="padding-top-16 text-center" style="color: #EB6100;font-size: 14px;">
            <p>温馨提示： &nbsp;&nbsp;&nbsp;&nbsp;1.具体上门时间以工程师预约时间为准 &nbsp;&nbsp;&nbsp;&nbsp;2.该维修价格为预计金额,实际金额以工程师检测故障为准</p>
          </div>
          <div class="padding-top-16 text-center">
            <button class="submit-button" @click="creatorder" :disabled='orderdisabled'>立即下单</button>
          </div>

        </div>

        <!--服务协议-->
        <el-dialog title="维修师服务协议" :visible.sync="protocolDialogVisible" width="85%" center top="1%">
          <wy-protocol></wy-protocol>
          <span slot="footer" class="dialog-footer">
            <el-button @click="protocolDialogVisible = false;customerInfo.protocol=false" style="padding: 5px 8px;">不同意
            </el-button>
            <el-button type="primary" @click="protocolDialogVisible = false;customerInfo.protocol=true"
              style="padding: 5px 8px;">阅读并同意</el-button>
          </span>
        </el-dialog>

      </div>
    </div>
  </div>
</template>

<script>
  import r from '../../utils/RequestUtilcopy'
  import wxs from '../utils/WxsService'
  import {
    Area
  } from '../../utils/Area'
  import WyBanner from './banner'
  import WyProtocol from './assembly/protocol'
  export default {
    name: 'confirmorder',
    components: {
      WyBanner,
      WyProtocol
    },
    data() {
      return {
        backg_c: "#0FAFEB",
        f_color: "#fff",
        disabled: false,
        timeTotal: 60,
        codeTips: "获取验证码",
        props: {
          value: 'label'
        },
        serviceType: [{
            label: '上门维修',
            value: 'SM'
          },
          {
            label: '到店维修',
            value: 'DD'
          }
        ],
        cityList: Area.areaList,
        selectcity: [],
        selectTime: [],
        customerInfo: {
          serviceType: "SM",
          brandName: '',
          modelName: '',
          deviceColor: '',
          price: 0,
          remark: '',
          orderElement: {
            province: '',
            city: '',
            county: '',
            address: '',
            customerName: '',
            telephoneNo: '',
          },
          orderService: {
            beginTime: "",
            endTime: "",
            shopId: null,
            shopName: ""
          },
          orderFailures: [],
          vcode: '',
          protocol: false
        },
        storeSlots: [],
        storeInfo: {},
        protocolDialogVisible: false,
        solutions: [],
        orderdisabled: false,
        selectShop: ''
      }
    },
    methods: {
      setCookie(name, value, time) {
        let strsec = time * 60 * 1000;
        let exp = new Date();
        exp.setTime(exp.getTime() + strsec * 1);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
      },
      //获取到服务方式
      selectserverType(model) {
        let serviceType = model;
        this.customerInfo.serviceType = serviceType;

        //到店时获取到所有店铺信息
        if (serviceType == "DD") {
          this.storeSlots = [{
            id: 1,
            shopName: '浦东张江店',
            name: '张经理',
            phone: '400-89891212',
            adrress: '浦东张江路88号'
          }, {
            id: 2,
            shopName: '杨浦延安店',
            name: '王经理',
            phone: '400-00009999',
            adrress: '杨浦延安路66号'
          }]
        }
      },
      //获取单个店铺信息
      showOneStore(storeId) {
        this.storeInfo = this.storeSlots[storeId - 1];
      },
      timeCount() {
        if (this.timeTotal > 0) {
          this.timeTotal--;
          this.codeTips = "重新发送(" + this.timeTotal + "s)";
        }
        let self = this;
        this.timer = setTimeout(function () {
          if (self.timeTotal === 0) {
            self.disabled = false;
            self.codeTips = "获取验证码";
            self.f_color = '#fff';
            self.backg_c = "#0FAFEB"
            self.timeTotal = 60;
            clearTimeout(self.timer);
          } else {
            self.timeCount();
          }
        }, 1000);
      },
      //提交订单
      creatorder() {

        //公用的数据
        if (this.customerInfo.orderElement.customerName == null || this.customerInfo.orderElement.customerName == "") {
          r.message("请输入您的姓名", "error")
          return;
        }
        if (this.customerInfo.orderElement.telephoneNo == null || this.customerInfo.orderElement.telephoneNo == "") {
          r.message("请输入电话号码", "error")
          return;
        }
        if (!this.customerInfo.protocol) {
          r.message("请阅读并同意《维修师服务协议》", "error")
          return;
        }
        let result = new Object();
        //服务方式是上门SM
        if (this.customerInfo.serviceType == "SM") {
          if (this.selectcity.length < 1) {
            r.message("请选择所在城市", "error")
            return;
          }
          if (this.customerInfo.orderElement.address == null || this.customerInfo.orderElement.address == "") {
            r.message("请输入具体地址", "error")
            return;
          }
          this.customerInfo.orderService.beginTime = null;
          this.customerInfo.orderService.endTime = null;

          this.customerInfo.orderElement.province = this.selectcity[0]; //省
          this.customerInfo.orderElement.city = this.selectcity[1]; //市
          this.customerInfo.orderElement.county = this.selectcity[2]; //县区
          this.customerInfo.orderService.shopId = null;
          this.customerInfo.orderService.shopName = "";

          result.serviceTypeName = '上门';
          result.province = this.selectcity[0];
          result.city = this.selectcity[1];
          result.county = this.selectcity[2];
          result.address = this.customerInfo.orderElement.address;
          result.beginTime = null;
          result.endTime = null;
          result.shopId = null;
          result.shopName = "";
        }

        //服务方式是到店DD
        if (this.customerInfo.serviceType == "DD") {
          if (this.selectTime.length < 1) {
            r.message("请输入到店时间", "error")
            return;
          }
          this.customerInfo.orderService.time = this.selectTime;
          this.customerInfo.orderElement.province = ""; //省
          this.customerInfo.orderElement.city = ""; //市
          this.customerInfo.orderElement.county = ""; //县区
          this.customerInfo.orderElement.address = ""; //具体地址
          this.customerInfo.orderService.shopId = this.storeInfo.id;
          this.customerInfo.orderService.shopName = this.storeInfo.shopName;

          result.serviceTypeName = '到店';
          result.time = this.selectTime;
          result.province = "";
          result.city = "";
          result.county = "";
          result.address = null;
          result.shopId = this.storeInfo.id;
          result.shopName = this.storeInfo.shopName;
        }
        this.setCookie('phoneNo', this.customerInfo.orderElement.telephoneNo, 3 * 60);
        result.status = '1';
        result.adminStatus = '01';
        result.adminStatusNo = "U";
        result.adminStatusName = '待处理';
        result.createTime = (new Date()).toLocaleString();
        result.No = Date.now().toString();
        if (this.orderdisabled == false) {
          this.orderdisabled = true;
        }
        setTimeout(function () {
          this.orderdisabled = false;
        }, 4000);

        let deviceInfo = JSON.parse(window.sessionStorage.getItem("deviceInfo"));

        result.failureDetailName = deviceInfo.faltDetail[0].name; //
        result.price = deviceInfo.faltDetail[0].price; //
        result.deviceColor = deviceInfo.color.name;
        result.serviceType = this.customerInfo.serviceType;
        result.flatName = deviceInfo.falt.name;
        result.failureDetailNo = deviceInfo.faltDetail[0].id; //
        result.modelName = deviceInfo.model.name;
        result.flatNo = deviceInfo.falt.id;
        result.brandName = deviceInfo.brand.name;
        result.modelNo = deviceInfo.model.No; //
        result.customerName = this.customerInfo.orderElement.customerName;
        result.phoneNo = this.customerInfo.orderElement.telephoneNo;
        result.address = this.customerInfo.orderElement.address;
        result.brandNo = deviceInfo.brand.id;
        result.actualPrice = '';
        console.log(result);
        wxs.addOrderInfo(result);
      }

    },
    mounted: function () {
      //从session中获取数据
      let deviceInfo = JSON.parse(window.sessionStorage.getItem("deviceInfo"));

      //赋值
      for (let solut of deviceInfo.faltDetail) {
        this.customerInfo.orderFailures.push({
          failureSubName: solut.name,
          price: solut.price,
          id: solut.id
        });
        this.customerInfo.price = this.customerInfo.price + parseInt(solut.price);
      }
      if (this.customerInfo.price == 0) {
        this.customerInfo.price = "待估价";
      }
      this.customerInfo.brandName = deviceInfo.brand.brandName;
      this.customerInfo.modelName = deviceInfo.model.name;
      this.customerInfo.deviceColor = deviceInfo.color.name;
      this.storeInfo = {
        id: 1,
        shopName: '浦东张江店',
        name: '张经理',
        phone: '400-89891212',
        adrress: '浦东张江路88号'
      };
    }
  }

</script>

<style scoped="scoped">
  @import url("./assets/css/index.css");

  .container {
    min-height: 600px;
  }

  .text-right {
    text-align: right;
  }

  .content {
    margin-top: 24px;
    margin-bottom: 24px;
    padding-top: 13px;
    padding-bottom: 13px;
  }

  .back-color-gray {
    background-color: #f7f7f7;
  }

  .text-style {
    font-size: 20px;
    color: #434343;
    line-height: 45px;
  }

  .padding-left-13 {
    padding-left: 13px;
  }

  .text-warning {
    font-size: 26px;
    color: #EB6100;
    padding-left: 5px;
    padding-right: 5px;
    line-height: 40px;
  }

  .el-form-item {
    height: 70px;
  }

  .item-label {
    font-size: 18px;
    color: #333;
    line-height: 70px;
  }

  .botton {
    width: 180px;
    line-height: 63px;
    font-size: 30px;
    color: #1A1A1A;
    text-align: center;
    margin-top: 4px;
    margin-right: 15px;
    border: 1px #e8e8e8 solid;
    border-radius: 2px;
    box-shadow: 1px 1px 3px #afafaf;
    cursor: pointer;
    float: left;
  }

  .select-server {
    border-color: #4FC1E9 !important;
    background-image: url(./assets/img/selected.png);
    background-repeat: no-repeat;
    background-position: top left;
  }

  .padding-top-16 {
    padding-top: 16px;
  }

  .padding-top-10 {
    padding-top: 10px;
  }

  .input-text {
    -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #4FC1E9;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 50px;
    line-height: 1;
    outline: 0;
    padding: 0 15px;
    -webkit-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
    transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
    width: 100%;

    -webkit-rtl-ordering: logical;
    cursor: text;

    text-rendering: auto;
    color: initial;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    margin: 0em;
    font: 400 13.3333px Arial;

    /* -webkit-writing-mode: horizontal-tb; */
  }

  .submit-button {
    color: #fff;
    width: 620px;
    height: 90px;
    background-color: #0FAFEB;
    font-size: 36px;
    border-radius: 8px;
    border: none;
    border-bottom: 5px solid #079ad1;
    cursor: pointer;
  }

  .submit-button:hover {
    background-color: #079AD1;
  }

  .border-info {
    border: #4FC1E9 1px solid;
    border-radius: 5px;
  }

  .font-style-primary {
    font-size: 14px;
    color: #0FAFEB;
    cursor: pointer;
  }

</style>
